set.seed(123456789)

# Relevant variables ------------------------------------------------------

# IPV

ipv_vars <- c("vaw_action",
							"should_intervene",
							"IPV_discussion")

# absenteeism

abs_vars <- c("absenteeism_action",
							"repeat_absence",
							"abs_discussion")



# abortion

abo_vars <- c("abo_action",
							"should_help",
							"abo_discussion")





# Relevant functions ------------------------------------------------------

getRIPval <- function(outcome, treatment, sims = sims){
	pvals <- get_RI_pvals(
		outcome = outcome,
		treatment = treatment,
		resample_FE = TRUE,
		block_FE = TRUE,
		audience_size = TRUE,
		cluster_SE = TRUE,
		covariates = NULL,
		the_data = subset(el, respondent_category == "Complier"),
		dosage = FALSE,
		dosage_indicator = FALSE,
		assignment_data = treatment_assignment,
		extract_function = coef,
		analysis_function = ols_main,
		sims = sims,
		lwr_upr_two = "upr")
	 pval <- pvals$ri_pvals[treatment]
	 return(pval)
}

ipv_pvals <- sapply(ipv_vars, getRIPval, treatment = "IPV", sims = sims)
abs_pvals <- sapply(abs_vars, getRIPval, treatment = "absenteeism", sims = sims)
abo_pvals <- sapply(abo_vars, getRIPval, treatment = "abortion", sims = sims)


table_data <- data.frame(outcome  = c("Conative attitudes VAW",
																			"Prescriptive norm VAW",
																			"Discussion VAW",
																			"Conative attitudes ABS",
																			"Prescriptive norm ABS",
																			"Discussion ABS",
																			"Conative attitudes ABO",
																			"Prescriptive norm ABO",
																			"Discussion ABO"),
												 pvalue = c(ipv_pvals, abs_pvals, abo_pvals))

table_data <- table_data[order(table_data$pvalue),]

table_data <- table_data %>%
	mutate(rank = 1:nrow(table_data),
				 critical_val01 = round(0.1*rank/nrow(table_data), 4),
				 critical_val02 = round(0.2*rank/nrow(table_data),4),
				 critical_val03 = round(0.3*rank/nrow(table_data),4))

table_data$pvalue	<- round(table_data$pvalue, 3)


sink("03_tables/multiple_comparisons_BH.tex")
print(kable(table_data, row.names = F, format = "latex",
			col.names = c("Outcome",
										"RI $p$-value",
										"Rank",
										"Critical Value $10\\%$",
										"Critical Value $20\\%$",
										"Critical Value $30\\%$"),
			align = c("l", rep("c",5)),
			escape = F
			))
sink()
